package com.inspire;

import com.process.ZoaThreadLocal;
import org.apache.hc.client5.http.classic.methods.HttpPost;
import org.apache.hc.client5.http.classic.methods.HttpUriRequestBase;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
import org.apache.hc.client5.http.impl.classic.HttpClients;
import org.apache.hc.core5.http.io.entity.EntityUtils;
import org.apache.hc.core5.http.io.entity.StringEntity;

public class Req1 {
    public static void main(String[] args) {
        // 目标 URL
        String url = "http://localhost:8080/TomcatWebProjJdk8-1.0-SNAPSHOT/hello-servlet";

        ZoaThreadLocal.G_Ins().A_CInfByID("gyt");
        // 创建 HttpClient 实例
        try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
            // 创建 POST 请求
            HttpPost httpPost = new HttpPost(url);

            // 设置请求头（如果需要）
            httpPost.setHeader("Content-Type", "application/json");
            httpPost.setHeader("Accept", "application/json");

            // 设置请求体（如果需要）
            String jsonBody = "{\"key1\":\"value1\", \"key2\":\"value2\"}";
            httpPost.setEntity(new StringEntity(jsonBody));

            // 发送请求并获取响应
            try (CloseableHttpResponse response = httpClient.execute(httpPost)) {
                // 获取响应状态码
                int statusCode = response.getCode();
                System.out.println("Response Status Code: " + statusCode);

                // 获取响应体
                String responseBody = EntityUtils.toString(response.getEntity());
                System.out.println("Response Body: " + responseBody);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}